// components/like/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    like: {
      type: Boolean,   // 必填，与vue相同
      value: false,    // 选填 值
      oberver: function(){  // 选填  属性值被更改时的响应函数

      }
    },
    count: {
      type: Number
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    likeSrc:'images/like.png',
    unlikeSrc: 'images/like@dis.png'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onLike(event){
      let like = this.properties.like
      let count = this.properties.count
      count = like ? count - 1 : count + 1 
      this.setData({
        count,
        like:!this.properties.like
      })
      let behavior = this.properties.like? 'like' :'cancel'
      this.triggerEvent('like',{
        behavior
      })
    }
  }
})
